package com.ad.pet.message.record;

import android.app.Activity;

import com.ad.pet.api.ApiService;
import com.ad.pet.app.RxDisposable;
import com.ad.pet.common.data.http.AppSubscriber;
import com.ad.pet.common.data.injector.PerActivity;
import com.ad.pet.common.structure.mvp.AbsBasePresenter;
import com.ad.pet.models.remote.CommList;
import com.ad.pet.models.remote.message.Record;

import java.util.List;

import javax.inject.Inject;

/**
 * Created by SEELE on 2019/7/4.
 */
@PerActivity
public class RecordPresenter  extends AbsBasePresenter implements RecordContract.Presenter{
    private ApiService mApiService;
    private RecordContract.View mView;

    private Activity mActivity;

    private RxDisposable mRxDisposable;

    @Inject
    public RecordPresenter(ApiService apiService,
                            Activity activity, RxDisposable rxDisposable) {
        mApiService = apiService;
        mActivity = activity;
        mRxDisposable = rxDisposable;
    }
    @Override
    public void onCreate(RecordContract.View view) {
        this.mView = view;
    }

    @Override
    public void onDestroy() {
        if (mRxDisposable!=null)
            mRxDisposable.clear();
        if (mActivity != null) mActivity = null;
        mView = null;
    }

    @Override
    public void getRecordList(String page, final String limit) {


        mRxDisposable.add(mApiService.get_transaction_log(page,limit)
                .subscribe(new AppSubscriber<CommList<List<Record>>>(mView) {
                    @Override
                    public void next(CommList<List<Record>> list) {
                        mView.getRecordListSuccess(list.getList());
                    }
                }));
    }




}
